package com.shanshan.crowd.mvc.controller;

import com.shanshan.crowd.entity.Auth;
import com.shanshan.crowd.service.api.AuthService;
import com.shanshan.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Description
 * @ClassName AuthController
 * @Author 山山大魔王
 * @Date 2022/7/25 22:36
 * @Version 1.0
 */
@RestController
public class AuthController {

    @Autowired
    private AuthService authService;

    ///assign/do/role/assign/auth.json
    @RequestMapping("/assign/do/role/assign/auth.json")
    public ResultEntity<String> saveRoleAuthRelathinship(@RequestBody Map<String,List<Integer>> map){
        authService.saveRoleAuthRelathinship(map);
        return ResultEntity.successWithoutData();
    }


    // "url":"/assign/get/assigned/auth/id/by/role/id.json",
    @RequestMapping("/assign/get/assigned/auth/id/by/role/id.json")
    public ResultEntity<List<Integer>> getAssignedAuthIdByRoleId(@RequestParam("roleId") Integer roleId){
        List<Integer> authIdList = authService.getAssignedAuthIdByRoleId(roleId);
        return ResultEntity.successWithData(authIdList);
    }

    @RequestMapping("/assign/get/assigned/menu/id/by/role/id.json")
    public ResultEntity<List<Integer>> getAssignedMenuIdByRoleId(@RequestParam("roleId") Integer roleId){
        List<Integer> authIdList = authService.getAssignedMenuIdByRoleId(roleId);
        return ResultEntity.successWithData(authIdList);
    }

    @RequestMapping("/assgin/get/all/auth.json")
    public ResultEntity<List<Auth>> getAllAuth(){
        List<Auth> authList =  authService.getAll();
        return ResultEntity.successWithData(authList);
    }


}
